home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 276-300 / 299 / rxil / src / create_rxi.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  4KB  |  190 lines

  1. /* create_rxi.c */
  2.  
  3. /*        Copyright © 1989 by Donald T. Meyer, Stormgate Software
  4.  *        All Rights Reserved
  5.  */
  6.  
  7.  
  8.  
  9. #include "rxil.h"
  10.  
  11. #include <exec/memory.h>
  12.  
  13.  
  14.  
  15. /* NAME
  16.  *        RxilCreateRxi
  17.  *
  18.  * SYNOPSIS
  19.  *        rxi = RxilCreateRxi( name, type );
  20.  *
  21.  *        struct RxilInvocation *rxi;
  22.  *
  23.  *        char *name;
  24.  *        ULONG type;
  25.  *
  26.  * FUNCTION
  27.  *        Allocate a RxilInvocation structure and initialize it to
  28.  *        the defaults which are contained in the global RxilDef
  29.  *        structure.
  30.  *
  31.  * INPUTS
  32.  *        name = character string containing the name of the ARexx
  33.  *            program that will be launched with the structure.
  34.  *        type = determines wether this will be used to launch commands
  35.  *            or functions.  Must be set to either RXCOMM or RXFUNC.
  36.  *
  37.  * RESULT
  38.  *        A pointer to a newly allocated and initialized RxilInvocation
  39.  *        structure, or NULL if one could not be allocated.
  40.  *
  41.  * SIDES
  42.  *
  43.  * HISTORY
  44.  *        01-Aug-89    Creation.
  45.  *
  46.  * BUGS
  47.  *
  48.  * SEE ALSO
  49.  *        RxilDeleteRxi()
  50.  */
  51.  
  52. struct RxilInvocation *RxilCreateRxi( char *name, ULONG type )
  53. {
  54.     struct RxilInvocation *rxi;
  55.  
  56.  
  57.     /* Make call "safe" even if RxilInit() failed */
  58.     if( global_rdef == NULL )
  59.     {
  60.         return( NULL );
  61.     }
  62.  
  63.     rxi = AllocMem( sizeof(struct RxilInvocation),
  64.         MEMF_PUBLIC | MEMF_CLEAR );
  65.     if( rxi == NULL )
  66.     {
  67.         return( NULL );
  68.     }
  69.  
  70.  
  71.     /* A little sanity check, combined with deciding which
  72.      * command address to default to.  (not anymore).
  73.      */
  74.     if( type == RXCOMM )
  75.     {
  76.         /* Command type macros default to having the secret port as
  77.          * their initial host address (if the secret port is open).
  78.          */
  79.         rxi->CommAddr = global_rdef->SecretPort ?
  80.             global_rdef->SecretPortName : global_rdef->PortName;
  81.     }
  82.     else
  83.     {
  84.         if( type == RXFUNC )
  85.         {
  86.             /* Functions default to returning results */
  87.             rxi->ActionFlags = RXFF_RESULT;
  88.  
  89.             /* Functions should have REXX as their initial host it
  90.              * seems to me.  Commands are the ones which would
  91.              * need to send commands back to the application. (???)
  92.              */
  93. /*            cad = "REXX"; */
  94.             /* On the other hand, Bill disagrees.  He's probably
  95.              * right...
  96.              */
  97.             rxi->CommAddr = global_rdef->SecretPort ?
  98.                 global_rdef->SecretPortName : global_rdef->PortName;
  99.         }
  100.         else
  101.         {
  102.             /* Invalid type flag bits */
  103.             FreeMem( rxi, sizeof(struct RxilInvocation) );
  104.             return( NULL );
  105.         }
  106.     }
  107.  
  108.  
  109.     /* Init the struct members */
  110.  
  111.     rxi->Type = type;
  112.     rxi->Name = name;
  113.  
  114.     /* Set these members to the values in the global default vars. */
  115.     rxi->FileExt = global_rdef->Extension;
  116.     rxi->IHostPort = global_rdef->HostPort;
  117.     rxi->Console = global_rdef->Console;
  118.  
  119.  
  120.     /* Add to our linked list for tracking purposes. */
  121.     rxi->Next = global_rdef->Invocations;
  122.     global_rdef->Invocations = rxi;
  123.  
  124.     return( rxi );
  125. }
  126.  
  127.  
  128.  
  129. /* NAME
  130.  *        RxilDeleteRxi
  131.  *
  132.  * SYNOPSIS
  133.  *        RxilDeleteRxi( rxi );
  134.  *
  135.  *        struct RxilInvocation *rxi;
  136.  *
  137.  * FUNCTION
  138.  *        Remove the structure allocated by a call to RxilCreateRxi() from
  139.  *        the linked list, and then frees it's memory.
  140.  *
  141.  * INPUTS
  142.  *        rxi = a pointer to the RxilInvocation structure to delete.
  143.  *            This must have been allocated by a call to RxilCreateRxi().
  144.  *
  145.  * RESULT
  146.  *        None
  147.  *
  148.  * SIDES
  149.  *
  150.  * HISTORY
  151.  *        01-Aug-89    Creation.
  152.  *
  153.  * BUGS
  154.  *
  155.  * SEE ALSO
  156.  *        RxilCreateRxi()
  157.  */
  158.  
  159. void RxilDeleteRxi( struct RxilInvocation *rxi )
  160. {
  161.      struct RxilInvocation **pred, *rxl;
  162.  
  163.  
  164.     /* Make call "safe" even if RxilInit() failed */
  165.     if( global_rdef == NULL )
  166.     {
  167.         return;
  168.     }
  169.  
  170.  
  171.     /* remove from the linked list */
  172.     pred = &(global_rdef->Invocations);
  173.  
  174.     for( rxl=global_rdef->Invocations; rxl; rxl=rxl->Next )
  175.     {
  176.         if( rxl == rxi )
  177.         {
  178.             /* Found the one we want to remove from the list */
  179.             *pred = rxi->Next;
  180.             break;
  181.         }
  182.  
  183.         pred = &rxi->Next;
  184.     }
  185.  
  186.     /* And delete. */
  187.     FreeMem( rxi, sizeof(struct RxilInvocation) );
  188. }
  189.  
  190.